/******************************************************************************
 * * sms_distribution.c - implementation of sms distribution functions
 *
 * *(C) Copyright 2019 Asr International Ltd.
 * * All Rights Reserved
 * ******************************************************************************/
#include "sms_include.h"

/**
 * sub-module entry
 * param (in) lv_obj_t *pBtn,lv_event_t event
 * return  VOID
 */
VOID Sms_Distribution_Lists(lv_obj_t *pBtn,lv_event_t event)
{
    // Distribution Lists function
    // create Messages_Distribution_Lists chart

    if(LV_EVENT_CLICKED != event)
    {
        return;
    }

    UINT32                       i       = 0;
    UINT32                       Cnt     = 0;
    INT8                         *str    = UI_Lang_Get_Text_ById(PHONE_TEXT_ID_EMPTY);
    Nav_Func_List_t              FuncList;
    UI_Normal_List_Only_Desc_t   *pDisList   = NULL;
    UI_Button_Desc_t             *ButtonList = NULL;
    Msg_Distribution_List_Info_t *pTemp      = NULL;
    UINT8                        *data       = Hal_Mem_Alloc(sizeof(NV_UI_Sms_Distribution_List_t));
    UINT8                        maxdistributionlistnum = NV_SMS_MAX_LIST_NUM;
    UINT8                        maxdraftnum = NV_SMS_MAX_DRAFTS_NUM;

    printf("maxdistributionlistnum is %d\n",maxdistributionlistnum);
    printf("maxdraftnum is %d\n",maxdraftnum);

    Hal_Mem_Set(data, 0, sizeof(NV_UI_Sms_Distribution_List_t));

    pDisList = (UI_Normal_List_Only_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Normal_List_Only_Desc_t));
    Hal_Mem_Set(pDisList, 0, sizeof(UI_Normal_List_Only_Desc_t));

    g_MsgGlobalCtrl.CurOpenBox = DISTRIBUTION_LISTS;
    g_MsgGlobalCtrl.pChart     = pDisList;

    pDisList->TitleBar.TxtId      = PHONE_TEXT_ID_DISTRIBUTION_LISTS;
    pDisList->TitleBar.TxtAlign   = LV_LABEL_ALIGN_CENTER;
    pDisList->TitleBar.LabelAlign = LV_ALIGN_IN_TOP_MID;

    pDisList->BtnBar.ButtonR.TxtId = PHONE_TEXT_ID_BACK;
    pDisList->BtnBar.ButtonR.Valid = true;

    pDisList->BtnBar.ButtonL.TxtId      = PHONE_TEXT_ID_OPT;
    pDisList->BtnBar.ButtonL.ReleaseFun = NULL;
    pDisList->BtnBar.ButtonL.Valid      = true;

    pDisList->KeyFunc = Sms_Distribution_Lists_Handle;

    FuncList.OnShow         = (Void_P_Func_t)UI_Normal_List_Only_Create;
    FuncList.OnHide         = NULL;
    FuncList.OnCreate       = Sms_Common_Create;
    FuncList.OnDestroy      = Sms_Distribution_Lists_Destory; // temp
    FuncList.OnSaveState    = Sms_Common_Save;                // temp
    FuncList.OnRestoreState = Sms_Common_Restore;             // temp

    // get the list name list from NV
    UI_NV_Read_Req(NV_SECTION_UI_SMS_DIST_LIST, 0, sizeof(NV_UI_Sms_Distribution_List_t), data);
    if (data[0])
    {
        g_MsgGlobalCtrl.pDisList = (Msg_Distribution_List_t *)Hal_Mem_Alloc(sizeof(Msg_Distribution_List_t));
        Hal_Mem_Set(g_MsgGlobalCtrl.pDisList, 0, sizeof(Msg_Distribution_List_t));
        g_MsgGlobalCtrl.pDisList->pDisListInfo = (lv_ll_t *)Hal_Mem_Alloc(sizeof(lv_ll_t));
        Hal_Mem_Set(g_MsgGlobalCtrl.pDisList->pDisListInfo, 0, sizeof(lv_ll_t));
        g_MsgGlobalCtrl.pDisList->DistriCnt = data[0];
        _lv_ll_init(g_MsgGlobalCtrl.pDisList->pDisListInfo, sizeof(Msg_Distribution_List_Info_t));
        for (i = 0; i < g_MsgGlobalCtrl.pDisList->DistriCnt; i++)
        {
            if (i)
            {
                pTemp = _lv_ll_ins_tail(g_MsgGlobalCtrl.pDisList->pDisListInfo);
                Hal_Mem_Set(pTemp, 0, sizeof(Msg_Distribution_List_Info_t));
            }
            else
            {
                pTemp = _lv_ll_ins_head(g_MsgGlobalCtrl.pDisList->pDisListInfo);
                Hal_Mem_Set(pTemp, 0, sizeof(Msg_Distribution_List_Info_t));
            }
            pTemp->NvAddrOffset = NV_SMS_MAX_NAME_NUM * NV_SMS_MAX_LIST_NUM * i + 1;
            pTemp->pListName    = Hal_Mem_Alloc(NV_SMS_MAX_NAME_NUM);
            Hal_Mem_Set(pTemp->pListName, 0, NV_SMS_MAX_NAME_NUM);
            Hal_Mem_Copy(pTemp->pListName, &(data[NV_SMS_MAX_NAME_NUM * i + 1]), NV_SMS_MAX_NAME_NUM);
        }
    }
    Hal_Mem_Free(data);
    data = NULL;
    if (NULL != g_MsgGlobalCtrl.pDisList)
    {
        Cnt = g_MsgGlobalCtrl.pDisList->DistriCnt;

        ButtonList = (UI_Button_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Button_Desc_t) * Cnt);
        Hal_Mem_Set(ButtonList, 0, sizeof(UI_Button_Desc_t) * Cnt);

        pDisList->List.ListButtonCnt = Cnt;
        pDisList->List.Index         = 0;
        pDisList->List.ButtonList    = ButtonList;

        for (i = 0; i < Cnt; i++)
        {
            if (i)
            {
                pTemp = _lv_ll_get_next(g_MsgGlobalCtrl.pDisList->pDisListInfo, pTemp);
            }
            else
            {
                pTemp = _lv_ll_get_head(g_MsgGlobalCtrl.pDisList->pDisListInfo);
            }
            ButtonList[i].ButtonIndex = i;
            ButtonList[i].TxtId       = LV_LANG_TXT_ID_NONE;
            ButtonList[i].BtnTxt      = pTemp->pListName;
            ButtonList[i].ReleaseFun  = NULL;
            ButtonList[i].Valid       = true;
        }
    }
    else
    {
        ButtonList = (UI_Button_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Button_Desc_t));
        Hal_Mem_Set(ButtonList, 0, sizeof(UI_Button_Desc_t));

        pDisList->List.ListButtonCnt = 1;
        pDisList->List.Index         = 0;
        pDisList->List.ButtonList    = ButtonList;

        ButtonList[0].ButtonIndex = 0;
        ButtonList[0].TxtId       = LV_LANG_TXT_ID_NONE;
        ButtonList[0].BtnTxt      = str;
        ButtonList[0].ReleaseFun  = NULL;
        ButtonList[0].Valid       = true;
    }
    Nav_Forward(ACT_ID_ANY, ACT_ID_MESSAGES_DISTRIBUTION_LISTS, &FuncList, (void *)pDisList);
} /* Sms_Distribution_Lists */

/**
 * Common Process UI destroy event
 * param (in) pDesc:  VOID *
 * return  void
 */
VOID Sms_Distribution_Lists_Destory(VOID *pDesc)
{
    UI_Normal_List_Only_Desc_t *pInput = pDesc;

    Hal_Mem_Free(pInput->List.ButtonList);
    pInput->List.ButtonList = NULL;
    Sms_Common_All_Global_Destory(pDesc);
}

/**
 * entry of message APP
 * param (in) void
 * return  void
 */
UINT8 Sms_Distribution_Lists_Handle(lv_obj_t *obj, UI_KEY_STATUS key_sta, UI_KEY_VALUE key_val)
{
    UINT8 Result = 0;

    // handle the return key
    if (KEY_RELEASED == key_sta)
    {
        if (KEY_SOFTRIGHT == key_val)
        {
            Nav_Back(ACT_ID_ANY);
            Result = 1;
        }
        else if (KEY_END == key_val)
        {
            Nav_Home(ACT_ID_ANY);
            Result = 1;
        }
        else if (KEY_SOFTLEFT == key_val)
        {
            Sms_Distribution_Lists_Opt(obj);
            Result = 1;
        }
    }

    return(Result);    // temp
}

/**
 * sub-module entry
 * param (in) lv_obj_t *pBtn
 * return  lv_res_t
 */
lv_res_t Sms_Distribution_Lists_Opt(lv_obj_t *pBtn)
{
    // Distribution Lists options function
    // create Messages_Distribution_Opt. chart
    UINT32                     i = 0;
    Nav_Func_List_t            FuncList;
    UI_Normal_List_Only_Desc_t *pDistriOpt = NULL;
    UI_Button_Desc_t           *ButtonList = NULL;
    INT8                       *pTemp      = NULL;
    lv_obj_t                   *pbutton;

    pDistriOpt = (UI_Normal_List_Only_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Normal_List_Only_Desc_t));
    Hal_Mem_Set(pDistriOpt, 0, sizeof(UI_Normal_List_Only_Desc_t));
    pbutton = lv_list_get_btn_selected(pBtn);
    pTemp   = lv_label_get_text(lv_obj_get_child(pbutton, NULL));
    i       = strlen(pTemp);
    if (i)
    {
        if (false != strcmp(pTemp, UI_Lang_Get_Text_ById(PHONE_TEXT_ID_EMPTY)))
        {
            Hal_Mem_Free(g_MsgGlobalCtrl.pDistriListName);
            g_MsgGlobalCtrl.pDistriListName = NULL;
            g_MsgGlobalCtrl.pDistriListName = Hal_Mem_Alloc(NV_SMS_MAX_NAME_NUM);
            Hal_Mem_Set(g_MsgGlobalCtrl.pDistriListName, 0, NV_SMS_MAX_NAME_NUM);
            strcpy(g_MsgGlobalCtrl.pDistriListName, pTemp);
        }
    }

    g_MsgGlobalCtrl.pChart = pDistriOpt;

    if (NULL != g_MsgGlobalCtrl.pDistriListName)
    {
        pDistriOpt->TitleBar.TxtId = LV_LANG_TXT_ID_NONE;
    }
    else
    {
        pDistriOpt->TitleBar.TxtId = PHONE_TEXT_ID_OPT;
    }

    pDistriOpt->TitleBar.TxtAlign   = LV_LABEL_ALIGN_CENTER;
    pDistriOpt->TitleBar.LabelAlign = LV_ALIGN_IN_TOP_MID;

    pDistriOpt->List.Index = 0;

    if (NULL != g_MsgGlobalCtrl.pDisList)
    {
        ButtonList = (UI_Button_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Button_Desc_t) * 5);
        Hal_Mem_Set(ButtonList, 0, sizeof(UI_Button_Desc_t) * 5);
        pDistriOpt->List.ListButtonCnt = 5;
        ButtonList[0].ButtonIndex      = 0;
        ButtonList[0].TxtId            = PHONE_TEXT_ID_VIEW_LIST;
        ButtonList[0].ReleaseFun       = Sms_Distribution_Lists_View_List;
        ButtonList[0].Valid            = true;
        ButtonList[1].ButtonIndex      = 1;
        ButtonList[1].TxtId            = PHONE_TEXT_ID_ADD_LIST;
        ButtonList[1].ReleaseFun       = Sms_Distribution_Lists_Add_List;
        ButtonList[1].Valid            = true;
        ButtonList[2].ButtonIndex      = 2;
        ButtonList[2].TxtId            = PHONE_TEXT_ID_SEND_SMS;
        ButtonList[2].ReleaseFun       = Sms_Distribution_Lists_Send_Sms;
        ButtonList[2].Valid            = true;
        ButtonList[3].ButtonIndex      = 3;
        ButtonList[3].TxtId            = PHONE_TEXT_ID_RENAME_LIST;
        ButtonList[3].ReleaseFun       = Sms_Distribution_Lists_Rename_List;
        ButtonList[3].Valid            = true;
        ButtonList[4].ButtonIndex      = 4;
        ButtonList[4].TxtId            = PHONE_TEXT_ID_DELETE_LIST;
        ButtonList[4].ReleaseFun       = Sms_Distribution_Lists_Delete_List;
        ButtonList[4].Valid            = true;
    }
    else
    {
        ButtonList = (UI_Button_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Button_Desc_t));
        Hal_Mem_Set(ButtonList, 0, sizeof(UI_Button_Desc_t));
        pDistriOpt->List.ListButtonCnt = 1;
        ButtonList[0].ButtonIndex      = 0;
        ButtonList[0].TxtId            = PHONE_TEXT_ID_ADD_LIST;
        ButtonList[0].ReleaseFun       = Sms_Distribution_Lists_Add_List;
        ButtonList[0].Valid            = true;
    }
    pDistriOpt->List.ButtonList = ButtonList;

    pDistriOpt->BtnBar.ButtonR.TxtId = PHONE_TEXT_ID_BACK;
    pDistriOpt->BtnBar.ButtonR.Valid = true;

    pDistriOpt->BtnBar.ButtonM.TxtId = PHONE_TEXT_ID_SELECT;
    pDistriOpt->BtnBar.ButtonM.Valid = true;

    pDistriOpt->KeyFunc = Sms_Distribution_Lists_Opt_Handle;

    FuncList.OnShow         = (Void_P_Func_t)UI_Normal_List_Only_Create;
    FuncList.OnHide         = NULL;
    FuncList.OnCreate       = Sms_Distribution_Lists_Opt_On_Create;
    FuncList.OnDestroy      = Sms_List_Only_Common_Destory;         // temp
    FuncList.OnSaveState    = Sms_Common_Save;                      // temp
    FuncList.OnRestoreState = Sms_Distribution_Lists_Opt_On_Create; // temp

    Nav_Forward(ACT_ID_ANY, ACT_ID_MESSAGES_DISTRIBUTION_OPT, &FuncList, (void *)pDistriOpt);

    return(LV_RES_OK);
} /* Sms_Distribution_Lists_Opt */

/**
 * Common Process UI Create event
 * param (in) pDesc:  VOID *
 * return  void
 */
VOID Sms_Distribution_Lists_Opt_On_Create(VOID *pDesc)
{
    UI_Normal_List_Only_Desc_t *pDistriOpt = NULL;

    g_MsgGlobalCtrl.pChart = pDesc;
    pDistriOpt             = g_MsgGlobalCtrl.pChart;

    if (NULL != g_MsgGlobalCtrl.pDistriListName)
    {
        lv_label_set_text(pDistriOpt->TitleBar.Label, g_MsgGlobalCtrl.pDistriListName);
    }
}

/**
 * entry of message APP
 * param (in) void
 * return  void
 */
UINT8 Sms_Distribution_Lists_Opt_Handle(lv_obj_t *obj, UI_KEY_STATUS key_sta, UI_KEY_VALUE key_val)
{
    UINT8 Result = 0;

    // handle the return key
    if (KEY_RELEASED == key_sta)
    {
        if (KEY_SOFTRIGHT == key_val)
        {
            Nav_Forward(ACT_ID_ANY, ACT_ID_MESSAGES, NULL, NULL);
            Sms_Distribution_Lists(NULL,LV_EVENT_CLICKED);
            Result = 1;
        }
        else if (KEY_END == key_val)
        {
            Nav_Home(ACT_ID_ANY);
            Result = 1;
        }
    }

    return(Result);    // temp
}

/**
 * sub-module entry
 * param (in) lv_obj_t *pBtn,lv_event_t event
 * return  VOID
 */
VOID Sms_Distribution_Lists_Add_List(lv_obj_t *pBtn,lv_event_t event)
{
    // Distribution Lists options add list function
    // create Messages_Distribution_Name chart

    Nav_Func_List_t                   FuncList;
    UI_Normal_NoTitle_Label_Ta_Desc_t *pDistriName = NULL;

    if(LV_EVENT_CLICKED != event)
    {
        return;
    }

    pDistriName = (UI_Normal_NoTitle_Label_Ta_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Normal_NoTitle_Label_Ta_Desc_t));
    Hal_Mem_Set(pDistriName, 0, sizeof(UI_Normal_NoTitle_Label_Ta_Desc_t));

    g_MsgGlobalCtrl.pChart = pDistriName;

    pDistriName->ContLabelTl.LabelAlign  = LV_ALIGN_IN_TOP_LEFT;
    pDistriName->ContLabelTl.TxtId       = LV_LANG_TXT_ID_NONE;
    pDistriName->ContLabelTl.SymbolAlign = LV_LABEL_ALIGN_CENTER;
    pDistriName->ContLabelTr.LabelAlign  = LV_ALIGN_IN_TOP_RIGHT;
    pDistriName->ContLabelTr.TxtId       = LV_LANG_TXT_ID_NONE;
    pDistriName->ContLabelTr.TxtAlign    = LV_LABEL_ALIGN_CENTER;
    pDistriName->ContLabel.LabelAlign    = LV_ALIGN_IN_TOP_MID;
    pDistriName->ContLabel.TxtId         = PHONE_TEXT_ID_LIST_NAME;
    pDistriName->ContLabel.TxtAlign      = LV_LABEL_ALIGN_LEFT;
    pDistriName->ContTa.TaCursorHide     = FALSE;
    pDistriName->ContTa.TaTxt            = NULL;

    pDistriName->ButtonCont.ButtonL.TxtId = PHONE_TEXT_ID_BACK;
    pDistriName->ButtonCont.ButtonL.Valid = true;

    pDistriName->ButtonCont.ButtonM.TxtId = PHONE_TEXT_ID_OK;
    pDistriName->ButtonCont.ButtonM.Valid = true;

    pDistriName->ButtonCont.ButtonR.TxtId = PHONE_TEXT_ID_CLEAR;
    pDistriName->ButtonCont.ButtonR.Valid = true;

    pDistriName->KeyFunc = Sms_Add_List_Handle;

    FuncList.OnShow         = (Void_P_Func_t)UI_Normal_NoTitle_Label_Ta_Create;
    FuncList.OnHide         = NULL;
    FuncList.OnCreate       = Sms_Add_List_On_Create;
    FuncList.OnDestroy      = Sms_Common_Destory; // temp
    FuncList.OnSaveState    = Sms_Common_Save;    // temp
    FuncList.OnRestoreState = Sms_Common_Restore; // temp

    Nav_Forward(ACT_ID_ANY, ACT_ID_MESSAGES_DISTRIBUTION_NAME, &FuncList, (void *)pDistriName);
} /* Sms_Distribution_Lists_Add_List */

/**
 * Process UI input char number event
 * param (in) pDesc:  VOID *
 * return  void
 */
VOID Sms_Add_List_Input_char_Process(UINT8 Len)
{
    UINT32                            i = 0;
    INT8                              Temp[MSG_TEXT_INPUT_MAX_LEN];
    INT8                              *pTemp       = NULL;
    UI_Normal_NoTitle_Label_Ta_Desc_t *pDistriName = g_MsgGlobalCtrl.pChart;

    pTemp = lv_label_get_text(pDistriName->ContLabelTr.Label);
    i     = atoi(pTemp);
    sprintf(Temp, "%d", (i - Len));
    lv_label_set_text(pDistriName->ContLabelTr.Label, Temp);
    lv_obj_set_hidden(pDistriName->ButtonCont.ButtonM.Button, FALSE);
}

/**
 * Common Process UI Create event
 * param (in) pDesc:  VOID *
 * return  void
 */
VOID Sms_Add_List_On_Create(VOID *pDesc)
{
    INT8                              Temp1[MSG_TEXT_INPUT_MAX_LEN];

    UI_Normal_NoTitle_Label_Ta_Desc_t *pDistriName = NULL;

    g_MsgGlobalCtrl.pChart = pDesc;
    pDistriName            = g_MsgGlobalCtrl.pChart;

    lv_textarea_set_max_length(pDistriName->ContTa.TextArea, MSG_ADD_LIST_MAX_LEN);
    lv_obj_set_hidden(pDistriName->ButtonCont.ButtonM.Button, TRUE);

    sprintf(Temp1, "%d", MSG_ADD_LIST_MAX_LEN);
    lv_label_set_text(pDistriName->ContLabelTr.Label, Temp1);
    Ime_Set_GetCharLen_Func(Sms_Add_List_Input_char_Process);
}

/**
 * sub-module entry
 * param (in) lv_obj_t *pBtn
 * return  UINT8
 */
UINT8 Sms_Add_List_Handle(lv_obj_t *obj, UI_KEY_STATUS key_sta, UI_KEY_VALUE key_val)
{
    UINT8                             Result = 0;
    UINT32                            i      = 0;
    UINT32                            j      = 0;
    INT8                              *pTemp;
    INT8                              Temp[MSG_TEXT_INPUT_MAX_LEN];
    Msg_Distribution_List_Info_t      *pNode       = NULL;
    NV_UI_Sms_Distribution_List_t     *data        = NULL;
    UI_Normal_NoTitle_Label_Ta_Desc_t *pDistriName = g_MsgGlobalCtrl.pChart;    // temp

    // handle the return key
    if (KEY_RELEASED == key_sta)
    {
        switch (key_val)
        {
        case KEY_0:
        case KEY_1:
        case KEY_2:
        case KEY_3:
        case KEY_4:
        case KEY_5:
        case KEY_6:
        case KEY_7:
        case KEY_8:
        case KEY_9:
        case KEY_ASTERISK:
            pTemp = (INT8 *)lv_textarea_get_text(obj);            // temp
            i     = strlen(pTemp);
            if(i < MSG_ADD_LIST_MAX_LEN)
            {
                sprintf(Temp, "%d", MSG_ADD_LIST_MAX_LEN - i - 1);
            }
            else
            {
                sprintf(Temp, "%d", 0);
                Result = 1;
            }
            lv_label_set_text(pDistriName->ContLabelTr.Label, Temp);
            lv_obj_set_hidden(pDistriName->ButtonCont.ButtonM.Button, FALSE);
            break;

        case KEY_SOFTRIGHT:
            lv_textarea_del_char(obj);
            pTemp = (INT8 *)lv_textarea_get_text(obj);
            i     = strlen(pTemp);
            sprintf(Temp, "%d", MSG_ADD_LIST_MAX_LEN - i);
            lv_label_set_text(pDistriName->ContLabelTr.Label, Temp);
            if (0 == i)
            {
                lv_obj_set_hidden(pDistriName->ButtonCont.ButtonM.Button, TRUE);
            }
            Result = 1;
            break;

        case KEY_SOFTLEFT:
            Nav_Back(ACT_ID_ANY);
            Result = 1;
            break;

        case KEY_OK:
            pTemp = (INT8 *)lv_textarea_get_text(obj);        // temp
            i     = strlen(pTemp);
            if (i)
            {            // ok
                if (NULL == g_MsgGlobalCtrl.pDisList)
                {
                    g_MsgGlobalCtrl.pDisList = (Msg_Distribution_List_t *)Hal_Mem_Alloc(sizeof(Msg_Distribution_List_t));
                    Hal_Mem_Set(g_MsgGlobalCtrl.pDisList, 0, sizeof(Msg_Distribution_List_t));
                    g_MsgGlobalCtrl.pDisList->DistriCnt    = 1;
                    g_MsgGlobalCtrl.pDisList->pDisListInfo = (lv_ll_t *)Hal_Mem_Alloc(sizeof(lv_ll_t));
                    Hal_Mem_Set(g_MsgGlobalCtrl.pDisList->pDisListInfo, 0, sizeof(lv_ll_t));
                    _lv_ll_init(g_MsgGlobalCtrl.pDisList->pDisListInfo, sizeof(Msg_Distribution_List_Info_t));
                    pNode = _lv_ll_ins_head(g_MsgGlobalCtrl.pDisList->pDisListInfo);
                    Hal_Mem_Set(pNode, 0, sizeof(Msg_Distribution_List_Info_t));
                    pNode->pListName = Hal_Mem_Alloc(NV_SMS_MAX_NAME_NUM);
                    Hal_Mem_Set(pNode->pListName, 0, NV_SMS_MAX_NAME_NUM);
                    strcpy(pNode->pListName, pTemp);
                    data                = (NV_UI_Sms_Distribution_List_t *)Hal_Mem_Alloc(sizeof(NV_UI_Sms_Distribution_List_t));
                    data->Count         = 1;
                    pNode->NvAddrOffset = 1;
                    strcpy(data->DistriList[0].ListName, pNode->pListName);
                    // set the new list name to nvm
                    UI_NV_Write_Req(NV_SECTION_UI_SMS_DIST_LIST, 0, sizeof(NV_UI_Sms_Distribution_List_t), (UINT8 *)data);
                    Hal_Mem_Free(data);
                    data = NULL;
                }
                else
                {
                    for (j = 0; j < g_MsgGlobalCtrl.pDisList->DistriCnt; j++)
                    {
                        if (j)
                        {
                            pNode = _lv_ll_get_next(g_MsgGlobalCtrl.pDisList->pDisListInfo, pNode);
                        }
                        else
                        {
                            pNode = _lv_ll_get_head(g_MsgGlobalCtrl.pDisList->pDisListInfo);
                        }
                        if (false == strcmp(pNode->pListName, pTemp))
                        {
                            Sms_Distribution_Lists_Name_Used();
                            Result = 1;
                            return(Result);
                        }
                    }

                    g_MsgGlobalCtrl.pDisList->DistriCnt++;
                    pNode = _lv_ll_ins_tail(g_MsgGlobalCtrl.pDisList->pDisListInfo);
                    Hal_Mem_Set(pNode, 0, sizeof(Msg_Distribution_List_Info_t));
                    pNode->pListName = Hal_Mem_Alloc(NV_SMS_MAX_NAME_NUM);
                    Hal_Mem_Set(pNode->pListName, 0, NV_SMS_MAX_NAME_NUM);
                    strcpy(pNode->pListName, pTemp);
                    data = (NV_UI_Sms_Distribution_List_t *)Hal_Mem_Alloc(sizeof(NV_UI_Sms_Distribution_List_t));
                    UI_NV_Read_Req(NV_SECTION_UI_SMS_DIST_LIST, 0, sizeof(NV_UI_Sms_Distribution_List_t), (UINT8 *)data);
                    if (data->Count < NV_SMS_MAX_LIST_NUM)
                    {
                        pNode->NvAddrOffset = data->Count * NV_SMS_MAX_NAME_NUM * NV_SMS_MAX_LIST_NUM + 1;
                        strcpy(data->DistriList[data->Count].ListName, pNode->pListName);
                        data->Count += 1;
                    }
                    else
                    {
                        /* distribution list is full */
                        Sms_Distribution_Lists_Full();
                        Result = 1;
                        return(Result);
                    }
                    // set the new list name to nvm
                    UI_NV_Write_Req(NV_SECTION_UI_SMS_DIST_LIST, 0, sizeof(NV_UI_Sms_Distribution_List_t), (UINT8 *)data);
                    Hal_Mem_Free(data);
                    data = NULL;
                }
                Sms_Distribution_Lists_Add_Name_OK(pNode->pListName);
            }
            Result = 1;
            break;

        case KEY_END:
            Nav_Home(ACT_ID_ANY);
            Result = 1;
            break;

        default:
            break;
        } /* switch */
    }
    else if (KEY_LONGPRESS == key_sta)
    {    // clear all
        if (KEY_SOFTRIGHT == key_val)
        {
            lv_textarea_set_text(obj, "");
            sprintf(Temp, "%d", MSG_ADD_LIST_MAX_LEN);
            lv_label_set_text(pDistriName->ContLabelTr.Label, Temp);
            lv_obj_set_hidden(pDistriName->ButtonCont.ButtonM.Button, TRUE);
        }
    }
    return(Result);   // temp
} /* Sms_Add_List_Handle */

/**
 * sub-module entry
 * param (in) VOID
 * return  VOID
 */
VOID Sms_Distribution_Lists_Full(VOID)
{
    // display contact full
    Nav_Func_List_t  FuncList;
    UI_Status_Desc_t *pAddSts = NULL;
    CB_FUNC          callback = Sms_Distribution_Lists_Full_Timeout;

    pAddSts = (UI_Status_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Status_Desc_t));
    Hal_Mem_Set(pAddSts, 0, sizeof(UI_Status_Desc_t));

    pAddSts->ContLabel.LabelAlign = LV_ALIGN_IN_TOP_LEFT;
    pAddSts->ContLabel.TxtId      = PHONE_TEXT_ID_LIST_FULL;

    pAddSts->ContLabel.TxtAlign = LV_LABEL_ALIGN_LEFT;
    pAddSts->ContLabelAlign     = LV_ALIGN_IN_TOP_LEFT;

    pAddSts->ContImg.Img      = LV_SYMBOL_WARNING;
    pAddSts->ContImg.ImgAlign = LV_ALIGN_IN_TOP_RIGHT;
    pAddSts->ContImgAlign     = LV_ALIGN_IN_TOP_RIGHT;

    FuncList.OnShow         = (Void_P_Func_t)UI_Status_Create;
    FuncList.OnHide         = NULL;
    FuncList.OnCreate       = Sms_Common_Create;
    FuncList.OnDestroy      = Sms_Common_Destory; // temp,delete all global
    FuncList.OnSaveState    = Sms_Common_Save;    // temp
    FuncList.OnRestoreState = Sms_Common_Restore; // temp

    Nav_Forward(ACT_ID_ANY, ACT_ID_MESSAGES_DISTRIBUTION_LIST_FULL, &FuncList, (void *)pAddSts);

    // 2s timer start
    Sms_Timer_Create_And_Start(callback, ACT_ID_MESSAGES_DISTRIBUTION_LIST_FULL);
}

/**
 * sub-module entry
 * param (in) VOID
 * return  VOID
 */
VOID Sms_Distribution_Lists_Full_Timeout(VOID* id)
{
    UINT32* Id = (UINT32 *)id;
    Nav_Forward(*Id, ACT_ID_MESSAGES_DISTRIBUTION_OPT, NULL, NULL);
}

/**
 * sub-module entry
 * param (in) VOID
 * return  VOID
 */
VOID Sms_Distribution_Lists_Name_Used(VOID)
{
    // create Messages_Distri_Add_Status chart
    Nav_Func_List_t  FuncList;
    UI_Status_Desc_t *pAddSts = NULL;
    CB_FUNC          callback = Sms_Distribution_Lists_Name_Used_Timeout;

    pAddSts = (UI_Status_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Status_Desc_t));
    Hal_Mem_Set(pAddSts, 0, sizeof(UI_Status_Desc_t));

    pAddSts->ContLabel.LabelAlign = LV_ALIGN_IN_TOP_LEFT;
    pAddSts->ContLabel.TxtId      = PHONE_TEXT_ID_NAME_ALREADY_IN_USE;

    pAddSts->ContLabel.TxtAlign = LV_LABEL_ALIGN_LEFT;
    pAddSts->ContLabelAlign     = LV_ALIGN_IN_TOP_LEFT;

    pAddSts->ContImg.Img      = LV_SYMBOL_WARNING;
    pAddSts->ContImg.ImgAlign = LV_ALIGN_IN_TOP_RIGHT;
    pAddSts->ContImgAlign     = LV_ALIGN_IN_TOP_RIGHT;

    FuncList.OnShow         = (Void_P_Func_t)UI_Status_Create;
    FuncList.OnHide         = NULL;
    FuncList.OnCreate       = Sms_Common_Create;
    FuncList.OnDestroy      = Sms_Common_Destory; // temp,delete all global
    FuncList.OnSaveState    = Sms_Common_Save;    // temp
    FuncList.OnRestoreState = Sms_Common_Restore; // temp

    Nav_Forward(ACT_ID_ANY, ACT_ID_MESSAGES_DISTRIBUTION_NAME_USED, &FuncList, (void *)pAddSts);

    // 2s timer start
    Sms_Timer_Create_And_Start(callback, ACT_ID_MESSAGES_DISTRIBUTION_NAME_USED);
}

/**
 * sub-module entry
 * param (in) VOID
 * return  VOID
 */
VOID Sms_Distribution_Lists_Name_Used_Timeout(VOID* id)
{
    UINT32* Id = (UINT32 *)id;
    Nav_Forward(*Id, ACT_ID_MESSAGES_DISTRIBUTION_NAME, NULL, NULL);
}

/**
 * sub-module entry
 * param (in) VOID
 * return  VOID
 */
VOID Sms_Distribution_Lists_Add_Name_OK(INT8 *name)
{
    // create Messages_Distri_Add_Status chart
    UINT32           i = 0;
    Nav_Func_List_t  FuncList;
    UI_Status_Desc_t *pAddSts = NULL;
    INT8             str[20];
    INT8             *pTemp   = NULL;
    CB_FUNC          callback = Sms_Distribution_Lists_Add_Name_Timeout;

    pAddSts = (UI_Status_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Status_Desc_t));
    Hal_Mem_Set(pAddSts, 0, sizeof(UI_Status_Desc_t));

    pAddSts->ContLabel.LabelAlign = LV_ALIGN_IN_TOP_LEFT;

    pAddSts->ContLabel.TxtId    = PHONE_TEXT_ID_ADDED;
    pAddSts->ContLabel.TxtAlign = LV_LABEL_ALIGN_LEFT;
    pAddSts->ContLabelAlign     = LV_ALIGN_IN_TOP_LEFT;

    pAddSts->ContImg.Img      = SYMBOL_CHECKED;
    pAddSts->ContImg.ImgAlign = LV_ALIGN_IN_TOP_RIGHT;
    pAddSts->ContImgAlign     = LV_ALIGN_IN_TOP_RIGHT;

    FuncList.OnShow         = (Void_P_Func_t)UI_Status_Create;
    FuncList.OnHide         = NULL;
    FuncList.OnCreate       = Sms_Common_Create;
    FuncList.OnDestroy      = Sms_Common_Destory; // temp,delete all global
    FuncList.OnSaveState    = Sms_Common_Save;    // temp
    FuncList.OnRestoreState = Sms_Common_Restore; // temp

    Nav_Forward(ACT_ID_ANY, ACT_ID_MESSAGES_DISTRI_ADD_STATUS, &FuncList, (void *)pAddSts);
    pTemp = (INT8 *)lv_label_get_text(pAddSts->ContLabel.Label);
    Hal_Mem_Set(str, 0, 20);
    pTemp = strcpy(str, pTemp);
    i     = strlen(name);

    pTemp = Hal_Mem_Alloc(i + 21);
    Hal_Mem_Set(pTemp, 0, i + 21);
    strcpy(pTemp, str);
    strcat(pTemp, name);
    lv_label_set_text(pAddSts->ContLabel.Label, pTemp);
    Hal_Mem_Free(pTemp);

    // 2s timer start
    Sms_Timer_Create_And_Start(callback, ACT_ID_MESSAGES_DISTRI_ADD_STATUS);
} /* Sms_Distribution_Lists_Add_Name_OK */

/**
 * sub-module entry
 * param (in) lv_obj_t *pBtn
 * return  lv_res_t
 */
VOID Sms_Distribution_Lists_Add_Name_Timeout(VOID* id)
{
    // Distribution Lists options add list name timeout function
    // create Messages_Distribution_Lists chart
    UINT32* Id = (UINT32 *)id;
    Nav_Forward(*Id, ACT_ID_MESSAGES, NULL, NULL);
    Sms_Distribution_Lists(NULL,LV_EVENT_CLICKED);
}

/**
 * sub-module entry
 * param (in) lv_obj_t *pBtn,lv_event_t event
 * return  VOID
 */
VOID Sms_Distribution_Lists_View_List(lv_obj_t *pBtn,lv_event_t event)
{
    // Distribution Lists options view list function
    // create Messages_Distribution_Body chart

    if(LV_EVENT_CLICKED != event)
    {
        return;
    }

    UINT32                                i     = 0;
    UINT32                                j     = 0;
    UINT32                                Cnt   = 0;
    INT8                                  str   = '\0';
    INT8                                  *str1 = UI_Lang_Get_Text_ById(PHONE_TEXT_ID_EMPTY);
    Nav_Func_List_t                       FuncList;
    UI_Normal_List_Only_Desc_t            *pViewList  = NULL;
    UI_Button_Desc_t                      *ButtonList = NULL;
    Msg_Distribution_List_Info_t          *pNode      = NULL;
    Msg_Contact_List_Info_t               *pTemp1     = NULL;
    NV_UI_Sms_Distribution_Contact_Name_t *data       = NULL;

    pViewList = (UI_Normal_List_Only_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Normal_List_Only_Desc_t));
    Hal_Mem_Set(pViewList, 0, sizeof(UI_Normal_List_Only_Desc_t));

    for (j = 0; j < g_MsgGlobalCtrl.pDisList->DistriCnt; j++)
    {
        if (j)
        {
            pNode = _lv_ll_get_next(g_MsgGlobalCtrl.pDisList->pDisListInfo, pNode);
        }
        else
        {
            pNode = _lv_ll_get_head(g_MsgGlobalCtrl.pDisList->pDisListInfo);
        }
        if (false == strcmp(pNode->pListName, g_MsgGlobalCtrl.pDistriListName))
        {
            break;
        }
    }
    // pNode->NvAddrOffset,get the nvm of contact list
    data = (NV_UI_Sms_Distribution_Contact_Name_t *)Hal_Mem_Alloc(sizeof(NV_UI_Sms_Distribution_Contact_Name_t));
    Hal_Mem_Set(data, 0, sizeof(NV_UI_Sms_Distribution_Contact_Name_t));
    UI_NV_Read_Req(NV_SECTION_UI_SMS_DIST_CONT_LIST, pNode->NvAddrOffset, sizeof(NV_UI_Sms_Distribution_Contact_Name_t), (UINT8 *)data);
    g_MsgGlobalCtrl.pContactInfo = (lv_ll_t *)Hal_Mem_Alloc(sizeof(lv_ll_t));
    Hal_Mem_Set(g_MsgGlobalCtrl.pContactInfo, 0, sizeof(lv_ll_t));
    _lv_ll_init(g_MsgGlobalCtrl.pContactInfo, sizeof(Msg_Contact_List_Info_t));

    for (i = 0; false != strcmp(data->ContactName[i], &str); i++)
    {
        if (NV_SMS_MAX_LIST_NUM == i)
        {
            break;
        }
        else
        {
            g_MsgGlobalCtrl.ContactCnt++;
        }
        if (i)
        {
            pTemp1 = _lv_ll_ins_tail(g_MsgGlobalCtrl.pContactInfo);
            Hal_Mem_Set(pTemp1, 0, sizeof(Msg_Contact_List_Info_t));
        }
        else
        {
            pTemp1 = _lv_ll_ins_head(g_MsgGlobalCtrl.pContactInfo);
            Hal_Mem_Set(pTemp1, 0, sizeof(Msg_Contact_List_Info_t));
        }
    }
    if (i)
    {
        Cnt = i;
        for (i = 0; i < Cnt; i++)
        {
            if (i)
            {
                pTemp1 = _lv_ll_get_next(g_MsgGlobalCtrl.pContactInfo, pTemp1);
            }
            else
            {
                pTemp1 = _lv_ll_get_head(g_MsgGlobalCtrl.pContactInfo);
            }
            pTemp1->pContact = Hal_Mem_Alloc(NV_SMS_MAX_NAME_NUM);
            Hal_Mem_Set(pTemp1->pContact, 0, NV_SMS_MAX_NAME_NUM);
            Hal_Mem_Copy(pTemp1->pContact, data->ContactName[i], NV_SMS_MAX_NAME_NUM);
            pTemp1->Index = i;
            pTemp1->pNum  = Contacts_Get_Contact_Number_Req(pTemp1->pContact);
            if (NULL == pTemp1->pNum)
            {
                _lv_ll_remove(g_MsgGlobalCtrl.pContactInfo, pTemp1);
                Hal_Mem_Free(pTemp1->pContact);
                pTemp1->pContact = NULL;
                Hal_Mem_Free(pTemp1);
                pTemp1 = NULL;
                g_MsgGlobalCtrl.ContactCnt--;
            }
        }
    }
    else
    {
        Sms_Common_Free_ContactInfo();
    }
    Hal_Mem_Set(data, 0, sizeof(NV_UI_Sms_Distribution_Contact_Name_t));
    for (i = 0; i < g_MsgGlobalCtrl.ContactCnt; i++)
    {
        if (i)
        {
            pTemp1 = _lv_ll_get_tail(g_MsgGlobalCtrl.pContactInfo);
        }
        else
        {
            pTemp1 = _lv_ll_get_head(g_MsgGlobalCtrl.pContactInfo);
        }
        Hal_Mem_Copy(data->ContactName[i], pTemp1->pContact, NV_SMS_MAX_NAME_NUM);
    }
    UI_NV_Write_Req(NV_SECTION_UI_SMS_DIST_CONT_LIST, pNode->NvAddrOffset, sizeof(NV_UI_Sms_Distribution_Contact_Name_t), (UINT8 *)data);
    UI_NV_Write_Req(NV_SECTION_UI_SMS_DIST_CONT_LIST, 0, 1, (UINT8 *)&g_MsgGlobalCtrl.ContactCnt);
    Hal_Mem_Free(data);
    data                   = NULL;
    g_MsgGlobalCtrl.pChart = pViewList;

    pViewList->TitleBar.TxtId      = LV_LANG_TXT_ID_NONE;
    pViewList->TitleBar.TxtAlign   = LV_LABEL_ALIGN_CENTER;
    pViewList->TitleBar.LabelAlign = LV_ALIGN_IN_TOP_MID;

    pViewList->BtnBar.ButtonR.TxtId = PHONE_TEXT_ID_BACK;
    pViewList->BtnBar.ButtonR.Valid = true;

    pViewList->BtnBar.ButtonL.TxtId = PHONE_TEXT_ID_OPT;
    pViewList->BtnBar.ButtonL.Valid = true;

    pViewList->KeyFunc = Sms_Distribution_Lists_View_List_Handle;

    FuncList.OnShow         = (Void_P_Func_t)UI_Normal_List_Only_Create;
    FuncList.OnHide         = NULL;
    FuncList.OnCreate       = Sms_Distribution_Lists_Opt_On_Create;
    FuncList.OnDestroy      = Sms_Send_To_Many_Sending_Rep_Destory; // temp
    FuncList.OnSaveState    = Sms_Common_Save;                      // temp
    FuncList.OnRestoreState = Sms_Distribution_Lists_Opt_On_Create; // temp
    i                       = 0;
    if (NULL != g_MsgGlobalCtrl.pContactInfo)
    {
        pTemp1 = _lv_ll_get_head(g_MsgGlobalCtrl.pContactInfo);
        for (i = 0; NULL != pTemp1; i++)
        {
            pTemp1 = _lv_ll_get_next(g_MsgGlobalCtrl.pContactInfo, pTemp1);
        }
    }

    if (i)
    {
        Cnt = i;

        ButtonList = (UI_Button_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Button_Desc_t) * Cnt);
        Hal_Mem_Set(ButtonList, 0, sizeof(UI_Button_Desc_t) * Cnt);

        pViewList->List.ListButtonCnt = Cnt;
        pViewList->List.Index         = 0;
        pViewList->List.ButtonList    = ButtonList;

        for (i = 0; i < Cnt; i++)
        {
            if (i)
            {
                pTemp1 = _lv_ll_get_next(g_MsgGlobalCtrl.pContactInfo, pTemp1);
            }
            else
            {
                pTemp1 = _lv_ll_get_head(g_MsgGlobalCtrl.pContactInfo);
            }
            ButtonList[i].ButtonIndex = i;
            ButtonList[i].TxtId       = LV_LANG_TXT_ID_NONE;
            ButtonList[i].BtnTxt      = pTemp1->pContact;
            ButtonList[i].Valid       = true;
        }
    }
    else
    {
        ButtonList = (UI_Button_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Button_Desc_t));
        Hal_Mem_Set(ButtonList, 0, sizeof(UI_Button_Desc_t));

        pViewList->List.ListButtonCnt = 1;
        pViewList->List.Index         = 0;
        pViewList->List.ButtonList    = ButtonList;

        ButtonList[0].ButtonIndex = 0;
        ButtonList[0].TxtId       = LV_LANG_TXT_ID_NONE;
        ButtonList[0].BtnTxt      = str1;
        ButtonList[0].Valid       = true;
    }
    Nav_Forward(ACT_ID_ANY, ACT_ID_MESSAGES_DISTRIBUTION_BODY, &FuncList, (void *)pViewList);
} /* Sms_Distribution_Lists_View_List */

/**
 * entry of message APP
 * param (in) void
 * return  void
 */
UINT8 Sms_Distribution_Lists_View_List_Handle(lv_obj_t *obj, UI_KEY_STATUS key_sta, UI_KEY_VALUE key_val)
{
    UINT8 Result = 0;

    // handle the return key
    if (KEY_RELEASED == key_sta)
    {
        if (KEY_SOFTRIGHT == key_val)
        {
            Nav_Back(ACT_ID_ANY);
            Result = 1;
        }
        else if (KEY_END == key_val)
        {
            Nav_Home(ACT_ID_ANY);
            Result = 1;
        }
        else if (KEY_SOFTLEFT == key_val)
        {
            Sms_Distribution_Lists_View_List_Opt(obj);
            Result = 1;
        }
    }

    return(Result);    // temp
}

/**
 * sub-module entry
 * param (in) lv_obj_t *pBtn
 * return  lv_res_t
 */
lv_res_t Sms_Distribution_Lists_View_List_Opt(lv_obj_t *pBtn)
{
    // Distribution Lists options view list option function
    // all list band this function
    // create Messages_Distri_Body_Opt. chart
    UINT32                     i = 0;
    Nav_Func_List_t            FuncList;
    UI_Normal_List_Only_Desc_t *pDistriBodyOpt = NULL;
    UI_Button_Desc_t           *ButtonList     = NULL;
    VOID                       *pTemp          = NULL;
    INT8                       *pTemp1         = NULL;
    lv_obj_t                   *pbutton;

    pDistriBodyOpt = (UI_Normal_List_Only_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Normal_List_Only_Desc_t));
    Hal_Mem_Set(pDistriBodyOpt, 0, sizeof(UI_Normal_List_Only_Desc_t));
    pbutton = lv_list_get_btn_selected(pBtn);
    pTemp1  = lv_label_get_text(lv_obj_get_child(pbutton, NULL));
    i       = strlen(pTemp1);
    if (i)
    {
        if (false != strcmp(pTemp1, UI_Lang_Get_Text_ById(PHONE_TEXT_ID_EMPTY)))
        {
            Hal_Mem_Free(g_MsgGlobalCtrl.pContact);
            g_MsgGlobalCtrl.pContact = NULL;
            g_MsgGlobalCtrl.pContact = Hal_Mem_Alloc(NV_SMS_MAX_NAME_NUM);
            Hal_Mem_Set(g_MsgGlobalCtrl.pContact, 0, NV_SMS_MAX_NAME_NUM);
            pTemp1 = strcpy(g_MsgGlobalCtrl.pContact, pTemp1);
        }
    }

    g_MsgGlobalCtrl.pChart = pDistriBodyOpt;

    pDistriBodyOpt->TitleBar.TxtId      = PHONE_TEXT_ID_OPT;
    pDistriBodyOpt->TitleBar.TxtAlign   = LV_LABEL_ALIGN_CENTER;
    pDistriBodyOpt->TitleBar.LabelAlign = LV_ALIGN_IN_TOP_MID;

    pDistriBodyOpt->List.Index = 0;
    pTemp                      = _lv_ll_get_head(g_MsgGlobalCtrl.pContactInfo);
    for (i = 0; NULL != pTemp; i++)
    {
        pTemp = _lv_ll_get_next(g_MsgGlobalCtrl.pContactInfo, pTemp);
    }
    if (i)
    {
        ButtonList = (UI_Button_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Button_Desc_t) * 3);
        Hal_Mem_Set(ButtonList, 0, sizeof(UI_Button_Desc_t) * 3);
        pDistriBodyOpt->List.ListButtonCnt = 3;
        ButtonList[0].ButtonIndex          = 0;
        ButtonList[0].TxtId                = PHONE_TEXT_ID_ADD_CONTACT;
        ButtonList[0].ReleaseFun           = Sms_Distribution_Lists_Add_Contact;
        ButtonList[0].Valid                = true;
        ButtonList[1].ButtonIndex          = 1;
        ButtonList[1].TxtId                = PHONE_TEXT_ID_VIEW_DETAILS;
        ButtonList[1].ReleaseFun           = Sms_Distribution_Lists_View_Details;
        ButtonList[1].Valid                = true;
        ButtonList[2].ButtonIndex          = 2;
        ButtonList[2].TxtId                = PHONE_TEXT_ID_RM_CONTACT;
        ButtonList[2].ReleaseFun           = Sms_Distribution_Lists_Remove_Contact;
        ButtonList[2].Valid                = true;
    }
    else
    {
        ButtonList = (UI_Button_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Button_Desc_t));
        Hal_Mem_Set(ButtonList, 0, sizeof(UI_Button_Desc_t));
        pDistriBodyOpt->List.ListButtonCnt = 1;
        ButtonList[0].ButtonIndex          = 0;
        ButtonList[0].TxtId                = PHONE_TEXT_ID_ADD_CONTACT;
        ButtonList[0].ReleaseFun           = Sms_Distribution_Lists_Add_Contact;
        ButtonList[0].Valid                = true;
    }
    pDistriBodyOpt->List.ButtonList = ButtonList;

    pDistriBodyOpt->BtnBar.ButtonR.TxtId = PHONE_TEXT_ID_BACK;
    pDistriBodyOpt->BtnBar.ButtonR.Valid = true;

    pDistriBodyOpt->BtnBar.ButtonM.TxtId = PHONE_TEXT_ID_SELECT;
    pDistriBodyOpt->BtnBar.ButtonM.Valid = true;

    pDistriBodyOpt->KeyFunc = Sms_Distribution_Lists_View_List_Opt_Handle;

    FuncList.OnShow         = (Void_P_Func_t)UI_Normal_List_Only_Create;
    FuncList.OnHide         = NULL;
    FuncList.OnCreate       = Sms_Common_Create;
    FuncList.OnDestroy      = Sms_List_Only_Common_Destory; // temp
    FuncList.OnSaveState    = Sms_Common_Save;              // temp
    FuncList.OnRestoreState = Sms_Common_Restore;           // temp

    Nav_Forward(ACT_ID_ANY, ACT_ID_MESSAGES_DISTRI_BODY_OPT, &FuncList, (void *)pDistriBodyOpt);

    return(LV_RES_OK);
} /* Sms_Distribution_Lists_View_List_Opt */

/**
 * entry of message APP
 * param (in) void
 * return  void
 */
UINT8 Sms_Distribution_Lists_View_List_Opt_Handle(lv_obj_t *obj, UI_KEY_STATUS key_sta, UI_KEY_VALUE key_val)
{
    UINT8 Result = 0;

    // handle the return key
    if (KEY_RELEASED == key_sta)
    {
        if (KEY_SOFTRIGHT == key_val)
        {
            Nav_Forward(ACT_ID_ANY, ACT_ID_MESSAGES_DISTRIBUTION_OPT, NULL, NULL);
            Sms_Distribution_Lists_View_List(NULL,LV_EVENT_CLICKED);
            Result = 1;
        }
        else if (KEY_END == key_val)
        {
            Nav_Home(ACT_ID_ANY);
            Result = 1;
        }
    }

    return(Result);   // temp
}

/**
 * sub-module entry
 * param (in) lv_obj_t *pBtn,lv_event_t event
 * return  VOID
 */
VOID Sms_Distribution_Lists_Add_Contact(lv_obj_t *pBtn,lv_event_t event)
{
    // Distribution Lists options view list option add contact function
    // go to Contacts,select the contact

    if(LV_EVENT_CLICKED != event)
    {
        return;
    }

    g_MsgGlobalCtrl.SelContactType = IF_CONTACTS_SMS_SEL_ONE_CONTACT;
    Contacts_Select_Contact_Req(IF_CONTACTS_SMS_SEL_ONE_CONTACT);
}

/**
 * sub-module entry
 * param (in) BOOL NameUsed:true or false
 * return  VOID
 */
VOID Sms_Distribution_Lists_Add_Contact_Cnf(BOOL NameUsed)
{
    // Distribution Lists options view list option add contact confirm function
    // if name already used,create Messages_Distribution_Name_Used chart
    // else create Messages_Distribution_Status chart
    Nav_Func_List_t  FuncList;
    UI_Status_Desc_t *pAddSts = NULL;
    CB_FUNC          callback = Sms_Distribution_Lists_Add_Contact_Cnf_Timeout;

    pAddSts = (UI_Status_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Status_Desc_t));
    Hal_Mem_Set(pAddSts, 0, sizeof(UI_Status_Desc_t));

    pAddSts->ContLabel.LabelAlign = LV_ALIGN_IN_TOP_LEFT;
    if (true == NameUsed)
    {
        pAddSts->ContLabel.TxtId = PHONE_TEXT_ID_NAME_ALREADY_IN_USE;
    }
    else
    {
        pAddSts->ContLabel.TxtId = PHONE_TEXT_ID_CONTACT_ADD_LIST;
    }
    pAddSts->ContLabel.TxtAlign = LV_LABEL_ALIGN_LEFT;
    pAddSts->ContLabelAlign     = LV_ALIGN_IN_TOP_LEFT;

    if (true == NameUsed)
    {
        pAddSts->ContImg.Img = LV_SYMBOL_WARNING;
    }
    else
    {
        pAddSts->ContImg.Img = SYMBOL_CHECKED;
    }
    pAddSts->ContImg.ImgAlign = LV_ALIGN_IN_TOP_RIGHT;
    pAddSts->ContImgAlign     = LV_ALIGN_IN_TOP_RIGHT;

    FuncList.OnShow         = (Void_P_Func_t)UI_Status_Create;
    FuncList.OnHide         = NULL;
    FuncList.OnCreate       = Sms_Common_Create;
    FuncList.OnDestroy      = Sms_Common_Destory; // temp,delete all global
    FuncList.OnSaveState    = Sms_Common_Save;    // temp
    FuncList.OnRestoreState = Sms_Common_Restore; // temp

    Nav_Forward(ACT_ID_ANY, ACT_ID_MESSAGES_DISTRIBUTION_STATUS, &FuncList, (void *)pAddSts);

    // 2s timer start
    Sms_Timer_Create_And_Start(callback, ACT_ID_MESSAGES_DISTRIBUTION_STATUS);
} /* Sms_Distribution_Lists_Add_Contact_Cnf */

/**
 * sub-module entry
 * param (in) BOOL NameUsed:true or false
 * return  VOID
 */
VOID Sms_Distribution_Lists_Add_Contact_Cnf_Timeout(VOID* id)
{
    UINT32* Id = (UINT32 *)id;
    Nav_Forward(*Id, ACT_ID_MESSAGES_DISTRI_BODY_OPT, NULL, NULL);
    g_MsgGlobalCtrl.SelContactType = IF_CONTACTS_SMS_SEL_ONE_CONTACT;
    Contacts_Select_Contact_Req(IF_CONTACTS_SMS_SEL_ONE_CONTACT);
}

/**
 * sub-module entry
 * param (in) VOID
 * return  VOID
 */
VOID Sms_Distribution_Lists_Contact_Full(VOID)
{
    // display contact full
    Nav_Func_List_t  FuncList;
    UI_Status_Desc_t *pAddSts = NULL;
    CB_FUNC          callback = Sms_Distribution_Lists_Contact_Full_Timeout;

    pAddSts = (UI_Status_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Status_Desc_t));
    Hal_Mem_Set(pAddSts, 0, sizeof(UI_Status_Desc_t));

    pAddSts->ContLabel.LabelAlign = LV_ALIGN_IN_TOP_LEFT;
    pAddSts->ContLabel.TxtId      = PHONE_TEXT_ID_LIST_FULL;

    pAddSts->ContLabel.TxtAlign = LV_LABEL_ALIGN_LEFT;
    pAddSts->ContLabelAlign     = LV_ALIGN_IN_TOP_LEFT;

    pAddSts->ContImg.Img      = LV_SYMBOL_WARNING;
    pAddSts->ContImg.ImgAlign = LV_ALIGN_IN_TOP_RIGHT;
    pAddSts->ContImgAlign     = LV_ALIGN_IN_TOP_RIGHT;

    FuncList.OnShow         = (Void_P_Func_t)UI_Status_Create;
    FuncList.OnHide         = NULL;
    FuncList.OnCreate       = Sms_Common_Create;
    FuncList.OnDestroy      = Sms_Common_Destory; // temp,delete all global
    FuncList.OnSaveState    = Sms_Common_Save;    // temp
    FuncList.OnRestoreState = Sms_Common_Restore; // temp

    Nav_Forward(ACT_ID_ANY, ACT_ID_MESSAGES_DISTRIBUTION_LIST_CONTACT_FULL, &FuncList, (void *)pAddSts);

    // 2s timer start
    Sms_Timer_Create_And_Start(callback, ACT_ID_MESSAGES_DISTRIBUTION_LIST_CONTACT_FULL);
}

/**
 * sub-module entry
 * param (in) VOID
 * return  VOID
 */
VOID Sms_Distribution_Lists_Contact_Full_Timeout(VOID* id)
{
    UINT32* Id = (UINT32 *)id;
    Nav_Forward(*Id, ACT_ID_MESSAGES_DISTRI_BODY_OPT, NULL, NULL);
}

/**
 * sub-module entry
 * param (in) lv_obj_t *pBtn,lv_event_t event
 * return  VOID
 */
VOID Sms_Distribution_Lists_View_Details(lv_obj_t *pBtn,lv_event_t event)
{
    // Distribution Lists options view list option view detail function
    // create Messages_Distri_Body_Details chart
    Nav_Func_List_t          FuncList;
    UI_Normal_Ta_Only_Desc_t *pReadMsg = NULL;

    if(LV_EVENT_CLICKED != event)
    {
        return;
    }

    pReadMsg = (UI_Normal_Ta_Only_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Normal_Ta_Only_Desc_t));
    Hal_Mem_Set(pReadMsg, 0, sizeof(UI_Normal_Ta_Only_Desc_t));

    pReadMsg->TitleBar.TxtId      = LV_LANG_TXT_ID_NONE;
    pReadMsg->TitleBar.LabelAlign = LV_ALIGN_IN_TOP_MID;
    pReadMsg->TitleBar.TxtAlign   = LV_LABEL_ALIGN_CENTER;

    pReadMsg->ContTa.TaAlign      = LV_ALIGN_IN_LEFT_MID;
    pReadMsg->ContTa.TaCursorHide = FALSE;
    pReadMsg->ContTa.TaTxt        = NULL;

    pReadMsg->ButtonBar.ButtonR.ButtonIndex = 0;
    pReadMsg->ButtonBar.ButtonR.Valid       = true;
    pReadMsg->ButtonBar.ButtonR.TxtId       = PHONE_TEXT_ID_BACK;
    pReadMsg->KeyFunc                       = Sms_Distribution_Lists_View_Details_Opt_Handle; // common

    FuncList.OnShow         = (Void_P_Func_t)UI_Normal_Ta_Only_Create;
    FuncList.OnHide         = NULL;
    FuncList.OnCreate       = Sms_View_Details_On_Create;
    FuncList.OnDestroy      = Sms_Common_Destory;         // temp
    FuncList.OnSaveState    = Sms_Common_Save;            // temp
    FuncList.OnRestoreState = Sms_View_Details_On_Create; // temp

    Nav_Forward(ACT_ID_ANY, ACT_ID_MESSAGES_DISTRI_BODY_DETAILS, &FuncList, (void *)pReadMsg);
}

/**
 * Common Process UI Create event
 * param (in) pDesc:  VOID *
 * return  void
 */
VOID Sms_View_Details_On_Create(VOID *pDesc)
{
    INT8                     str       = '\n';
    INT8                     *str1     = UI_Lang_Get_Text_ById(PHONE_TEXT_ID_NUMBER_COLON);
    INT8                     *str2     = UI_Lang_Get_Text_ById(PHONE_TEXT_ID_NAMED_COLON);
    Msg_Contact_List_Info_t  *pNode    = NULL;
    UINT8                    j         = 0;
    UI_Normal_Ta_Only_Desc_t *pReadMsg = NULL;

    g_MsgGlobalCtrl.pChart = pDesc;
    pReadMsg               = g_MsgGlobalCtrl.pChart;

    for (j = 0; j < g_MsgGlobalCtrl.ContactCnt; j++)
    {
        if (j)
        {
            pNode = _lv_ll_get_next(g_MsgGlobalCtrl.pContactInfo, pNode);
        }
        else
        {
            pNode = _lv_ll_get_head(g_MsgGlobalCtrl.pContactInfo);
        }
        if (false == strcmp(g_MsgGlobalCtrl.pContact, pNode->pContact))
        {
            break;
        }
    }
    lv_label_set_text(pReadMsg->TitleBar.Label, g_MsgGlobalCtrl.pContact);
    lv_textarea_set_text(pReadMsg->ContTa.TextArea, str2);
    lv_textarea_add_char(pReadMsg->ContTa.TextArea, str);
    lv_textarea_add_text(pReadMsg->ContTa.TextArea, g_MsgGlobalCtrl.pContact);
    lv_textarea_add_char(pReadMsg->ContTa.TextArea, str);
    lv_textarea_add_text(pReadMsg->ContTa.TextArea, str1);
    lv_textarea_add_char(pReadMsg->ContTa.TextArea, str);
    lv_textarea_add_text(pReadMsg->ContTa.TextArea, pNode->pNum);
}

/**
 * entry of message APP
 * param (in) void
 * return  void
 */
UINT8 Sms_Distribution_Lists_View_Details_Opt_Handle(lv_obj_t *obj, UI_KEY_STATUS key_sta, UI_KEY_VALUE key_val)
{
    UINT8 Result = 0;

    // handle the return key
    if (KEY_RELEASED == key_sta)
    {
        if (KEY_SOFTRIGHT == key_val)
        {
            Nav_Back(ACT_ID_ANY);
            Result = 1;
        }
        else if (KEY_END == key_val)
        {
            Nav_Home(ACT_ID_ANY);
            Result = 1;
        }
    }

    return(Result);   // temp
}

/**
 * sub-module entry
 * param (in) lv_obj_t *pBtn,lv_event_t event
 * return  VOID
 */
VOID Sms_Distribution_Lists_Remove_Contact(lv_obj_t *pBtn,lv_event_t event)
{
    // Distribution Lists options view list option remove contact function
    // create Messages_Distri_Body_Remove chart
    Nav_Func_List_t          FuncList;
    UI_Normal_NoTitle_Desc_t *pRemoveContact = NULL;
    INT8                     *pTemp          = NULL;
    INT8                     *pTemp1         = NULL;

    if(LV_EVENT_CLICKED != event)
    {
        return;
    }

    pRemoveContact = (UI_Normal_NoTitle_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Normal_NoTitle_Desc_t));
    Hal_Mem_Set(pRemoveContact, 0, sizeof(UI_Normal_NoTitle_Desc_t));

    g_MsgGlobalCtrl.pChart = pRemoveContact;

    pRemoveContact->ContenCont.ContLabel.LabelAlign = LV_ALIGN_IN_TOP_LEFT;
    pRemoveContact->ContenCont.ContLabel.TxtId      = LV_LANG_TXT_ID_NONE;
    pRemoveContact->ContenCont.ContLabel.TxtAlign   = LV_LABEL_ALIGN_LEFT;
    pRemoveContact->ContenCont.ContLabelAlign       = LV_ALIGN_IN_TOP_LEFT;

    pRemoveContact->ButtonBar.ButtonR.TxtId = PHONE_TEXT_ID_BACK;
    pRemoveContact->ButtonBar.ButtonR.Valid = true;

    pRemoveContact->ButtonBar.ButtonM.TxtId = PHONE_TEXT_ID_OK;
    pRemoveContact->ButtonBar.ButtonM.Valid = true;

    pRemoveContact->KeyFunc = Sms_Distribution_Lists_Remove_Contact_Handle;     // common

    FuncList.OnShow         = (Void_P_Func_t)UI_Normal_NoTitle_Create;
    FuncList.OnHide         = NULL;
    FuncList.OnCreate       = Sms_Common_Create;
    FuncList.OnDestroy      = Sms_Common_Destory; // temp
    FuncList.OnSaveState    = Sms_Common_Save;    // temp
    FuncList.OnRestoreState = Sms_Common_Restore; // temp

    Nav_Forward(ACT_ID_ANY, ACT_ID_MESSAGES_DISTRI_BODY_REMOVE, &FuncList, (void *)pRemoveContact);

    pTemp  = (INT8 *)lv_lang_get_text(PHONE_TEXT_ID_RM_FROM_LIST_Q);
    pTemp1 = Hal_Mem_Alloc(strlen(pTemp) + strlen(g_MsgGlobalCtrl.pContact) + 1);
    Hal_Mem_Set(pTemp1, 0, strlen(pTemp) + strlen(g_MsgGlobalCtrl.pContact) + 1);
    strcpy(pTemp1, pTemp);
    strcat(pTemp1, g_MsgGlobalCtrl.pContact);
    lv_label_set_text(pRemoveContact->ContenCont.ContLabel.Label, pTemp1);
    Hal_Mem_Free(pTemp1);
    pTemp1 = NULL;
} /* Sms_Distribution_Lists_Remove_Contact */

/**
 * entry of message APP
 * param (in) void
 * return  void
 */
UINT8 Sms_Distribution_Lists_Remove_Contact_Handle(lv_obj_t *obj, UI_KEY_STATUS key_sta, UI_KEY_VALUE key_val)
{
    UINT8 Result = 0;

    // handle the return key
    if (KEY_RELEASED == key_sta)
    {
        if (KEY_SOFTRIGHT == key_val)
        {
            Nav_Back(ACT_ID_ANY);
            Result = 1;
        }
        else if (KEY_OK == key_val)
        {
            Sms_Distribution_Lists_Remove_Contact_List(NULL);
            Result = 1;
        }
        else if (KEY_END == key_val)
        {
            Nav_Home(ACT_ID_ANY);
            Result = 1;
        }
    }

    return(Result);   // temp
}

/**
 * sub-module entry
 * param (in) lv_obj_t *pBtn
 * return  lv_res_t
 */
lv_res_t Sms_Distribution_Lists_Remove_Contact_List(lv_obj_t *pBtn)
{
    // Distribution Lists options view list option remove contact list function
    // band all contacts this function
    // create Messages_Distri_Remove_Status chart
    UINT32                                i       = 0;
    UINT32                                j       = 0;
    UINT32                                k       = 0;
    Msg_Distribution_List_Info_t          *pNode  = NULL;
    Msg_Contact_List_Info_t               *pTemp1 = NULL;
    NV_UI_Sms_Distribution_Contact_Name_t *data   = NULL;
    NV_UI_Sms_Distribution_Contact_Name_t *data1  = NULL;
    Nav_Func_List_t                       FuncList;
    UI_Status_Desc_t                      *pRemoveStatus = NULL;
    CB_FUNC                               callback       = Sms_Distribution_Lists_Remove_Contact_Timeout;

    pRemoveStatus = (UI_Status_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Status_Desc_t));
    Hal_Mem_Set(pRemoveStatus, 0, sizeof(UI_Status_Desc_t));

    pRemoveStatus->ContLabel.LabelAlign = LV_ALIGN_IN_TOP_LEFT;
    pRemoveStatus->ContLabel.TxtId      = PHONE_TEXT_ID_REMOVED;
    pRemoveStatus->ContLabel.TxtAlign   = LV_LABEL_ALIGN_LEFT;
    pRemoveStatus->ContLabelAlign       = LV_ALIGN_IN_TOP_LEFT;

    pRemoveStatus->ContImg.Img      = SYMBOL_CHECKED;
    pRemoveStatus->ContImg.ImgAlign = LV_ALIGN_IN_TOP_RIGHT;
    pRemoveStatus->ContImgAlign     = LV_ALIGN_IN_TOP_RIGHT;

    FuncList.OnShow         = (Void_P_Func_t)UI_Status_Create;
    FuncList.OnHide         = NULL;
    FuncList.OnCreate       = Sms_Common_Create;
    FuncList.OnDestroy      = Sms_Common_Destory; // temp
    FuncList.OnSaveState    = Sms_Common_Save;    // temp
    FuncList.OnRestoreState = Sms_Common_Restore; // temp

    Nav_Forward(ACT_ID_ANY, ACT_ID_MESSAGES_DISTRI_REMOVE_STATUS, &FuncList, (void *)pRemoveStatus);
    for (j = 0; j < g_MsgGlobalCtrl.pDisList->DistriCnt; j++)
    {
        if (j)
        {
            pNode = _lv_ll_get_next(g_MsgGlobalCtrl.pDisList->pDisListInfo, pNode);
        }
        else
        {
            pNode = _lv_ll_get_head(g_MsgGlobalCtrl.pDisList->pDisListInfo);
        }
        if (false == strcmp(pNode->pListName, g_MsgGlobalCtrl.pDistriListName))
        {
            break;
        }
    }

    // pNode->NvAddrOffset,get the nvm of contact list
    data = (NV_UI_Sms_Distribution_Contact_Name_t *)Hal_Mem_Alloc(sizeof(NV_UI_Sms_Distribution_Contact_Name_t));
    Hal_Mem_Set(data, 0, sizeof(NV_UI_Sms_Distribution_Contact_Name_t));
    UI_NV_Read_Req(NV_SECTION_UI_SMS_DIST_CONT_LIST, pNode->NvAddrOffset, sizeof(NV_UI_Sms_Distribution_Contact_Name_t), (UINT8 *)data);
    for (i = 0; i < NV_SMS_MAX_LIST_NUM; i++)
    {
        if (i)
        {
            pTemp1 = _lv_ll_get_next(g_MsgGlobalCtrl.pContactInfo, pTemp1);
        }
        else
        {
            pTemp1 = _lv_ll_get_head(g_MsgGlobalCtrl.pContactInfo);
        }

        if (false == strcmp(data->ContactName[i], g_MsgGlobalCtrl.pContact))
        {
            _lv_ll_remove(g_MsgGlobalCtrl.pContactInfo, pTemp1);
            g_MsgGlobalCtrl.ContactCnt -= 1;
            Hal_Mem_Free(pTemp1);
            pTemp1 = NULL;
            Hal_Mem_Free(g_MsgGlobalCtrl.pContact);
            g_MsgGlobalCtrl.pContact = NULL;
            if (NULL == _lv_ll_get_head(g_MsgGlobalCtrl.pContactInfo))
            {
                Sms_Common_Free_ContactInfo();
            }
            break;
        }
    }
    data1 = (NV_UI_Sms_Distribution_Contact_Name_t *)Hal_Mem_Alloc(sizeof(NV_UI_Sms_Distribution_Contact_Name_t));
    Hal_Mem_Set(data1, 0, sizeof(NV_UI_Sms_Distribution_Contact_Name_t));
    for (j = 0; false != strcmp(data->ContactName[j], "\0"); j++)
    {
        if (j != i)
        {
            strcpy(data1->ContactName[k], data->ContactName[j]);
            k++;
        }
    }
    UI_NV_Write_Req(NV_SECTION_UI_SMS_DIST_CONT_LIST, pNode->NvAddrOffset, sizeof(NV_UI_Sms_Distribution_Contact_Name_t), (UINT8 *)data1);
    Hal_Mem_Free(data);
    data = NULL;
    Hal_Mem_Free(data1);
    data1 = NULL;

    // 2s timer start
    Sms_Timer_Create_And_Start(callback, ACT_ID_MESSAGES_DISTRI_REMOVE_STATUS);
    return(LV_RES_OK);
} /* Sms_Distribution_Lists_Remove_Contact_List */

/**
 * sub-module entry
 * param (in) lv_obj_t *pBtn
 * return  lv_res_t
 */
VOID Sms_Distribution_Lists_Remove_Contact_Timeout(VOID* id)
{
    // go to Messages_Distribution_Body
    UINT32* Id = (UINT32 *)id;
    Nav_Forward(*Id, ACT_ID_MESSAGES_DISTRIBUTION_OPT, NULL, NULL);
    Sms_Distribution_Lists_View_List(NULL,LV_EVENT_CLICKED);
}

/**
 * sub-module entry
 * param (in) lv_obj_t *pBtn,lv_event_t event
 * return  VOID
 */
VOID Sms_Distribution_Lists_Send_Sms(lv_obj_t *pBtn,lv_event_t event)
{
    // Distribution Lists options Send sms function
    // if distribution list is empty,create Messages_Distribution_List_Empty chart,2s timer start
    // if not empty,create Messages_Create_Message chart,Sms_Create
    UINT32                                i       = 0;
    INT8                                  str     = '\0';
    Msg_Distribution_List_Info_t          *pNode  = NULL;
    Msg_Contact_List_Info_t               *pNode1 = NULL;
    NV_UI_Sms_Distribution_Contact_Name_t *data   = NULL;

    if(LV_EVENT_CLICKED != event)
    {
        return;
    }

    for (i = 0; i < g_MsgGlobalCtrl.pDisList->DistriCnt; i++)
    {
        if (i)
        {
            pNode = _lv_ll_get_next(g_MsgGlobalCtrl.pDisList->pDisListInfo, pNode);
        }
        else
        {
            pNode = _lv_ll_get_head(g_MsgGlobalCtrl.pDisList->pDisListInfo);
        }
        if (false == strcmp(pNode->pListName, g_MsgGlobalCtrl.pDistriListName))
        {
            break;
        }
    }
    if (NULL == g_MsgGlobalCtrl.pContactInfo)
    {
        // get list from nvm to g_MsgGlobalCtrl.ContactCnt and g_MsgGlobalCtrl.pContactInfo with freenum
        data = (NV_UI_Sms_Distribution_Contact_Name_t *)Hal_Mem_Alloc(sizeof(NV_UI_Sms_Distribution_Contact_Name_t));
        Hal_Mem_Set(data, 0, sizeof(NV_UI_Sms_Distribution_Contact_Name_t));
        UI_NV_Read_Req(NV_SECTION_UI_SMS_DIST_CONT_LIST, pNode->NvAddrOffset, sizeof(NV_UI_Sms_Distribution_Contact_Name_t), (UINT8 *)data);
        g_MsgGlobalCtrl.SuccessCnt   = 0;
        g_MsgGlobalCtrl.ContactCnt   = 0;
        g_MsgGlobalCtrl.pContactInfo = (lv_ll_t *)Hal_Mem_Alloc(sizeof(lv_ll_t));
        Hal_Mem_Set(g_MsgGlobalCtrl.pContactInfo, 0, sizeof(lv_ll_t));
        _lv_ll_init(g_MsgGlobalCtrl.pContactInfo, sizeof(Msg_Contact_List_Info_t));
        for (i = 0; false != strcmp(data->ContactName[i], &str); i++)
        {
            if (NV_SMS_MAX_LIST_NUM == i)
            {
                break;
            }
            else
            {
                g_MsgGlobalCtrl.ContactCnt++;
            }
            if (i)
            {
                pNode1 = _lv_ll_ins_tail(g_MsgGlobalCtrl.pContactInfo);
                Hal_Mem_Set(pNode1, 0, sizeof(Msg_Contact_List_Info_t));
            }
            else
            {
                pNode1 = _lv_ll_ins_head(g_MsgGlobalCtrl.pContactInfo);
                Hal_Mem_Set(pNode1, 0, sizeof(Msg_Contact_List_Info_t));
            }
            pNode1->Index    = i;
            pNode1->pContact = Hal_Mem_Alloc(NV_SMS_MAX_NAME_NUM);
            Hal_Mem_Set(pNode1->pContact, 0, NV_SMS_MAX_NAME_NUM);
            Hal_Mem_Copy(pNode1->pContact, data->ContactName[i], NV_SMS_MAX_NAME_NUM);
            pNode1->pNum = Contacts_Get_Contact_Number_Req(pNode1->pContact);
            if (NULL == pNode1->pNum)
            {
                _lv_ll_remove(g_MsgGlobalCtrl.pContactInfo, pNode1);
                Hal_Mem_Free(pNode1->pContact);
                pNode1->pContact = NULL;
                Hal_Mem_Free(pNode1);
                pNode1 = NULL;
                g_MsgGlobalCtrl.ContactCnt--;
            }
        }
        Hal_Mem_Set(data, 0, sizeof(NV_UI_Sms_Distribution_Contact_Name_t));
        for (i = 0; i < g_MsgGlobalCtrl.ContactCnt; i++)
        {
            if (i)
            {
                pNode1 = _lv_ll_get_tail(g_MsgGlobalCtrl.pContactInfo);
            }
            else
            {
                pNode1 = _lv_ll_get_head(g_MsgGlobalCtrl.pContactInfo);
            }
            Hal_Mem_Copy(data->ContactName[i], pNode1->pContact, NV_SMS_MAX_NAME_NUM);
        }
        UI_NV_Write_Req(NV_SECTION_UI_SMS_DIST_CONT_LIST, pNode->NvAddrOffset, sizeof(NV_UI_Sms_Distribution_Contact_Name_t), (UINT8 *)data);
        UI_NV_Write_Req(NV_SECTION_UI_SMS_DIST_CONT_LIST, 0, 1, (UINT8 *)&g_MsgGlobalCtrl.ContactCnt);
        if (0 == g_MsgGlobalCtrl.ContactCnt)
        {
            Sms_Common_Free_ContactInfo();
            Sms_Distribution_Lists_Distri_Empty(NULL);
            return;
        }
        Hal_Mem_Free(data);
        data = NULL;
    }
    Sms_Create(NULL,LV_EVENT_CLICKED);
} /* Sms_Distribution_Lists_Send_Sms */

/**
 * sub-module entry
 * param (in) lv_obj_t *pBtn
 * return  lv_res_t
 */
lv_res_t Sms_Distribution_Lists_Distri_Empty(lv_obj_t *pBtn)
{
    // create Messages_Distribution_List_Empty chart
    Nav_Func_List_t  FuncList;
    UI_Status_Desc_t *pListEmpty = NULL;
    CB_FUNC          callback    = Sms_Distribution_Lists_Distri_Empty_Timeout;

    pListEmpty = (UI_Status_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Status_Desc_t));
    Hal_Mem_Set(pListEmpty, 0, sizeof(UI_Status_Desc_t));

    pListEmpty->ContLabel.LabelAlign = LV_ALIGN_IN_TOP_LEFT;
    pListEmpty->ContLabel.TxtId      = PHONE_TEXT_ID_DISTRIBUTION_LIST_EMPTY;
    pListEmpty->ContLabel.TxtAlign   = LV_LABEL_ALIGN_LEFT;
    pListEmpty->ContLabelAlign       = LV_ALIGN_IN_TOP_LEFT;

    pListEmpty->ContImg.Img      = LV_SYMBOL_WARNING;
    pListEmpty->ContImg.ImgAlign = LV_ALIGN_IN_TOP_RIGHT;
    pListEmpty->ContImgAlign     = LV_ALIGN_IN_TOP_RIGHT;

    FuncList.OnShow         = (Void_P_Func_t)UI_Status_Create;
    FuncList.OnHide         = NULL;
    FuncList.OnCreate       = Sms_Common_Create;
    FuncList.OnDestroy      = Sms_Common_Destory; // temp
    FuncList.OnSaveState    = Sms_Common_Save;    // temp
    FuncList.OnRestoreState = Sms_Common_Restore; // temp

    Nav_Forward(ACT_ID_ANY, ACT_ID_MESSAGES_DISTRIBUTION_LIST_EMPTY, &FuncList, (void *)pListEmpty);

    // 2s timer start
    Sms_Timer_Create_And_Start(callback, ACT_ID_MESSAGES_DISTRIBUTION_LIST_EMPTY);
    return(LV_RES_OK);
}

/**
 * sub-module entry
 * param (in)
 * return  VOID
 */
VOID Sms_Distribution_Lists_Distri_Empty_Timeout(VOID* id)
{
    // create Messages_Sending_Options chart
    UINT32* Id = (UINT32 *)id;
    Nav_Forward(*Id, ACT_ID_MESSAGES_DISTRIBUTION_LISTS, NULL, NULL);
}

/**
 * sub-module entry
 * param (in) lv_obj_t *pBtn,lv_event_t event
 * return  VOID
 */
VOID Sms_Distribution_Lists_Rename_List(lv_obj_t *pBtn,lv_event_t event)
{
    // Distribution Lists options Rename list function

    Nav_Func_List_t                   FuncList;
    UI_Normal_NoTitle_Label_Ta_Desc_t *pDistriName = NULL;

    if(LV_EVENT_CLICKED != event)
    {
        return;
    }

    pDistriName = (UI_Normal_NoTitle_Label_Ta_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Normal_NoTitle_Label_Ta_Desc_t));
    Hal_Mem_Set(pDistriName, 0, sizeof(UI_Normal_NoTitle_Label_Ta_Desc_t));

    g_MsgGlobalCtrl.pChart = pDistriName;

    pDistriName->ContLabelTl.LabelAlign  = LV_ALIGN_IN_TOP_LEFT;
    pDistriName->ContLabelTl.TxtId       = LV_LANG_TXT_ID_NONE;
    pDistriName->ContLabelTl.SymbolAlign = LV_LABEL_ALIGN_CENTER;
    pDistriName->ContLabelTr.LabelAlign  = LV_ALIGN_IN_TOP_RIGHT;
    pDistriName->ContLabelTr.TxtId       = LV_LANG_TXT_ID_NONE;
    pDistriName->ContLabelTr.TxtAlign    = LV_LABEL_ALIGN_CENTER;
    pDistriName->ContLabel.LabelAlign    = LV_ALIGN_IN_TOP_MID;
    pDistriName->ContLabel.TxtId         = PHONE_TEXT_ID_LIST_NAME;
    pDistriName->ContLabel.TxtAlign      = LV_LABEL_ALIGN_LEFT;
    pDistriName->ContTa.TaCursorHide     = FALSE;

    pDistriName->ButtonCont.ButtonL.TxtId = PHONE_TEXT_ID_BACK;
    pDistriName->ButtonCont.ButtonL.Valid = true;
    pDistriName->ContTa.TaTxt             = NULL;

    pDistriName->ButtonCont.ButtonM.TxtId = PHONE_TEXT_ID_OK;
    pDistriName->ButtonCont.ButtonM.Valid = true;

    pDistriName->ButtonCont.ButtonR.TxtId = PHONE_TEXT_ID_CLEAR;
    pDistriName->ButtonCont.ButtonR.Valid = true;

    pDistriName->KeyFunc = Sms_Rename_List_Handle;

    FuncList.OnShow         = (Void_P_Func_t)UI_Normal_NoTitle_Label_Ta_Create;
    FuncList.OnHide         = NULL;
    FuncList.OnCreate       = Sms_Add_List_On_Create;
    FuncList.OnDestroy      = Sms_Common_Destory; // temp
    FuncList.OnSaveState    = Sms_Common_Save;    // temp
    FuncList.OnRestoreState = Sms_Common_Restore; // temp

    Nav_Forward(ACT_ID_ANY, ACT_ID_MESSAGES_DISTRIBUTION_NAME, &FuncList, (void *)pDistriName);
} /* Sms_Distribution_Lists_Rename_List */

/**
 * sub-module entry
 * param (in) lv_obj_t *pBtn
 * return  UINT8
 */
UINT8 Sms_Rename_List_Handle(lv_obj_t *obj, UI_KEY_STATUS key_sta, UI_KEY_VALUE key_val)
{
    UINT8                              Result = 0;
    UINT32                             i      = 0;
    UINT32                             j      = 0;
    INT8                               *pTemp;
    INT8                               Temp[MSG_TEXT_INPUT_MAX_LEN];
    NV_UI_Sms_Distribution_List_Name_t *data        = NULL;
    Msg_Distribution_List_Info_t       *pNode       = NULL;
    Msg_Distribution_List_Info_t       *pNode1      = NULL;
    UI_Normal_NoTitle_Label_Ta_Desc_t  *pDistriName = g_MsgGlobalCtrl.pChart;   // temp

    // handle the return key
    if (KEY_RELEASED == key_sta)
    {
        switch (key_val)
        {
        case KEY_0:
        case KEY_1:
        case KEY_2:
        case KEY_3:
        case KEY_4:
        case KEY_5:
        case KEY_6:
        case KEY_7:
        case KEY_8:
        case KEY_9:
        case KEY_ASTERISK:
            pTemp = (INT8 *)lv_textarea_get_text(obj);            // temp
            i     = strlen(pTemp);
            if(i < MSG_ADD_LIST_MAX_LEN)
            {
                sprintf(Temp, "%d", MSG_ADD_LIST_MAX_LEN - i - 1);
            }
            else
            {
                sprintf(Temp, "%d", 0);
                Result = 1;
            }
            lv_label_set_text(pDistriName->ContLabelTr.Label, Temp);
            lv_obj_set_hidden(pDistriName->ButtonCont.ButtonM.Button, FALSE);
            break;

        case KEY_SOFTRIGHT:
            lv_textarea_del_char(obj);
            pTemp = (INT8 *)lv_textarea_get_text(obj);
            i     = strlen(pTemp);
            sprintf(Temp, "%d", MSG_ADD_LIST_MAX_LEN - i);
            lv_label_set_text(pDistriName->ContLabelTr.Label, Temp);
            if (0 == i)
            {
                lv_obj_set_hidden(pDistriName->ButtonCont.ButtonM.Button, TRUE);
            }
            Result = 1;
            break;

        case KEY_SOFTLEFT:
            Nav_Back(ACT_ID_ANY);
            Result = 1;
            break;

        case KEY_OK:
            pTemp = (INT8 *)lv_textarea_get_text(obj);        // temp

            i = strlen(pTemp);
            if (i)
            {            // ok
                for (j = 0; j < g_MsgGlobalCtrl.pDisList->DistriCnt; j++)
                {
                    if (j)
                    {
                        pNode1 = _lv_ll_get_next(g_MsgGlobalCtrl.pDisList->pDisListInfo, pNode1);
                    }
                    else
                    {
                        pNode1 = _lv_ll_get_head(g_MsgGlobalCtrl.pDisList->pDisListInfo);
                    }
                    if (false == strcmp(pNode1->pListName, pTemp))
                    {
                        Sms_Distribution_Lists_Name_Used();
                        Result = 1;
                        return(Result);
                    }
                }

                for (j = 0; j < g_MsgGlobalCtrl.pDisList->DistriCnt; j++)
                {
                    if (j)
                    {
                        pNode = _lv_ll_get_next(g_MsgGlobalCtrl.pDisList->pDisListInfo, pNode);
                    }
                    else
                    {
                        pNode = _lv_ll_get_head(g_MsgGlobalCtrl.pDisList->pDisListInfo);
                    }
                    if (false == strcmp(pNode->pListName, g_MsgGlobalCtrl.pDistriListName))
                    {
                        break;
                    }
                }

                Hal_Mem_Free(pNode->pListName);
                pNode->pListName = NULL;
                pNode->pListName = Hal_Mem_Alloc(NV_SMS_MAX_NAME_NUM);
                Hal_Mem_Set(pNode->pListName, 0, NV_SMS_MAX_NAME_NUM);
                strcpy(pNode->pListName, pTemp);
                strcpy(g_MsgGlobalCtrl.pDistriListName, pTemp);
                // set the new list name to nvm
                data = (NV_UI_Sms_Distribution_List_Name_t *)Hal_Mem_Alloc(sizeof(NV_UI_Sms_Distribution_List_Name_t));
                Hal_Mem_Set(data, 0, sizeof(NV_UI_Sms_Distribution_List_Name_t));
                Hal_Mem_Copy(data->ListName, pNode->pListName, NV_SMS_MAX_NAME_NUM);
                UI_NV_Write_Req(NV_SECTION_UI_SMS_DIST_LIST, NV_SMS_MAX_NAME_NUM * j + 1, sizeof(NV_UI_Sms_Distribution_List_Name_t), (UINT8 *)data);
                Hal_Mem_Free(data);
                data = NULL;
                Sms_Distribution_Lists_Rename_OK(pNode->pListName);
            }
            Result = 1;
            break;

        case KEY_END:
            Nav_Home(ACT_ID_ANY);
            Result = 1;
            break;

        default:
            break;
        } /* switch */
    }
    else if (KEY_LONGPRESS == key_sta)
    {    // clear all
        if (KEY_SOFTRIGHT == key_val)
        {
            lv_textarea_set_text(obj, "");
            sprintf(Temp, "%d", MSG_ADD_LIST_MAX_LEN);
            lv_label_set_text(pDistriName->ContLabelTr.Label, Temp);
            lv_obj_set_hidden(pDistriName->ButtonCont.ButtonM.Button, TRUE);
        }
    }
    return(Result);   // temp
} /* Sms_Rename_List_Handle */

/**
 * sub-module entry
 * param (in) VOID
 * return  VOID
 */
VOID Sms_Distribution_Lists_Rename_OK(INT8 *name)
{
    // create Messages_Distri_Rename_Status chart
    UINT32           i = 0;
    Nav_Func_List_t  FuncList;
    UI_Status_Desc_t *pRenameSts = NULL;
    INT8             str[20];
    INT8             *pTemp   = NULL;
    CB_FUNC          callback = Sms_Distribution_Lists_Add_Name_Timeout;

    pRenameSts = (UI_Status_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Status_Desc_t));
    Hal_Mem_Set(pRenameSts, 0, sizeof(UI_Status_Desc_t));

    pRenameSts->ContLabel.LabelAlign = LV_ALIGN_IN_TOP_LEFT;

    pRenameSts->ContLabel.TxtId = PHONE_TEXT_ID_RENAMED;

    pRenameSts->ContLabel.TxtAlign = LV_LABEL_ALIGN_LEFT;
    pRenameSts->ContLabelAlign     = LV_ALIGN_IN_TOP_LEFT;

    pRenameSts->ContImg.Img      = SYMBOL_CHECKED;
    pRenameSts->ContImg.ImgAlign = LV_ALIGN_IN_TOP_RIGHT;
    pRenameSts->ContImgAlign     = LV_ALIGN_IN_TOP_RIGHT;

    FuncList.OnShow         = (Void_P_Func_t)UI_Status_Create;
    FuncList.OnHide         = NULL;
    FuncList.OnCreate       = Sms_Common_Create;
    FuncList.OnDestroy      = Sms_Common_Destory; // temp,delete all global
    FuncList.OnSaveState    = Sms_Common_Save;    // temp
    FuncList.OnRestoreState = Sms_Common_Restore; // temp

    Nav_Forward(ACT_ID_ANY, ACT_ID_MESSAGES_DISTRI_RENAME_STATUS, &FuncList, (void *)pRenameSts);
    pTemp = (INT8 *)lv_label_get_text(pRenameSts->ContLabel.Label);
    Hal_Mem_Set(str, 0, 20);
    pTemp = strcpy(str, pTemp);
    i     = strlen(name);

    pTemp = Hal_Mem_Alloc(i + 21);
    Hal_Mem_Set(pTemp, 0, i + 21);
    strcpy(pTemp, str);
    strcat(pTemp, name);
    lv_label_set_text(pRenameSts->ContLabel.Label, pTemp);
    Hal_Mem_Free(pTemp);
    // 2s timer start
    Sms_Timer_Create_And_Start(callback, ACT_ID_MESSAGES_DISTRI_RENAME_STATUS);
    // call back:Sms_Distribution_Lists_Add_Name_Timeout
} /* Sms_Distribution_Lists_Rename_OK */

/**
 * sub-module entry
 * param (in) lv_obj_t *pBtn,lv_event_t event
 * return  VOID
 */
VOID Sms_Distribution_Lists_Delete_List(lv_obj_t *pBtn,lv_event_t event)
{
    // Distribution Lists options delete list function
    Nav_Func_List_t          FuncList;
    UI_Normal_NoTitle_Desc_t *pDeleteList = NULL;

    if(LV_EVENT_CLICKED != event)
    {
        return;
    }

    pDeleteList = (UI_Normal_NoTitle_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Normal_NoTitle_Desc_t));
    Hal_Mem_Set(pDeleteList, 0, sizeof(UI_Normal_NoTitle_Desc_t));

    g_MsgGlobalCtrl.pChart = pDeleteList;

    pDeleteList->ContenCont.ContLabel.LabelAlign = LV_ALIGN_IN_TOP_LEFT;
    pDeleteList->ContenCont.ContLabel.TxtId      = PHONE_TEXT_ID_DEL_DIS_LIST;
    pDeleteList->ContenCont.ContLabel.TxtAlign   = LV_LABEL_ALIGN_LEFT;
    pDeleteList->ContenCont.ContLabelAlign       = LV_ALIGN_IN_TOP_LEFT;

    pDeleteList->ButtonBar.ButtonR.TxtId = PHONE_TEXT_ID_BACK;
    pDeleteList->ButtonBar.ButtonR.Valid = true;

    pDeleteList->ButtonBar.ButtonM.TxtId = PHONE_TEXT_ID_OK;
    pDeleteList->ButtonBar.ButtonM.Valid = true;

    pDeleteList->KeyFunc = Sms_Delete_List_Handle;     // common

    FuncList.OnShow         = (Void_P_Func_t)UI_Normal_NoTitle_Create;
    FuncList.OnHide         = NULL;
    FuncList.OnCreate       = Sms_Common_Create;
    FuncList.OnDestroy      = Sms_Common_Destory; // temp
    FuncList.OnSaveState    = Sms_Common_Save;    // temp
    FuncList.OnRestoreState = Sms_Common_Restore; // temp

    Nav_Forward(ACT_ID_ANY, ACT_ID_MESSAGES_DISTRI_LIST_DELETE, &FuncList, (void *)pDeleteList);
}

/**
 * entry of message APP
 * param (in) lv_obj_t * obj, UI_KEY_STATUS key_sta, UI_KEY_VALUE key_val
 * return  UINT8
 */
UINT8 Sms_Delete_List_Handle(lv_obj_t *obj, UI_KEY_STATUS key_sta, UI_KEY_VALUE key_val)
{
    UINT8 Result = 0;

    // handle the return key
    if (KEY_RELEASED == key_sta)
    {
        if (KEY_SOFTRIGHT == key_val)
        {
            Nav_Back(ACT_ID_ANY);
            Result = 1;
        }
        else if (KEY_OK == key_val)
        {
            Sms_Distribution_Lists_Delete_List_OK(NULL);
            Result = 1;
        }
        else if (KEY_END == key_val)
        {
            Nav_Home(ACT_ID_ANY);
            Result = 1;
        }
    }

    return(Result);   // temp
}

/**
 * sub-module entry
 * param (in) lv_obj_t *pBtn
 * return  lv_res_t
 */
lv_res_t Sms_Distribution_Lists_Delete_List_OK(lv_obj_t *pBtn)
{
    UINT32                                 j      = 0;
    UINT32                                 k      = 0;
    NV_UI_Sms_Distribution_List_t          *data  = NULL;
    NV_UI_Sms_Distribution_Contacts_List_t *data1 = NULL;
    NV_UI_Sms_Distribution_Contacts_List_t *data2 = NULL;
    Nav_Func_List_t                        FuncList;
    UI_Status_Desc_t                       *pDeleteSts = NULL;
    INT8                                   str[20];
    INT8                                   *pTemp   = NULL;
    CB_FUNC                                callback = Sms_Distribution_Lists_Add_Name_Timeout;
    Msg_Distribution_List_Info_t           *pNode   = NULL;

    pDeleteSts = (UI_Status_Desc_t *)Hal_Mem_Alloc(sizeof(UI_Status_Desc_t));
    Hal_Mem_Set(pDeleteSts, 0, sizeof(UI_Status_Desc_t));

    pDeleteSts->ContLabel.LabelAlign = LV_ALIGN_IN_TOP_LEFT;

    pDeleteSts->ContLabel.TxtId    = PHONE_TEXT_ID_DELETED_COLON;
    pDeleteSts->ContLabel.TxtAlign = LV_LABEL_ALIGN_LEFT;
    pDeleteSts->ContLabelAlign     = LV_ALIGN_IN_TOP_LEFT;

    pDeleteSts->ContImg.Img      = SYMBOL_CHECKED;
    pDeleteSts->ContImg.ImgAlign = LV_ALIGN_IN_TOP_RIGHT;
    pDeleteSts->ContImgAlign     = LV_ALIGN_IN_TOP_RIGHT;

    FuncList.OnShow         = (Void_P_Func_t)UI_Status_Create;
    FuncList.OnHide         = NULL;
    FuncList.OnCreate       = Sms_Common_Create;
    FuncList.OnDestroy      = Sms_Common_Destory; // temp,delete all global
    FuncList.OnSaveState    = Sms_Common_Save;    // temp
    FuncList.OnRestoreState = Sms_Common_Restore; // temp

    Nav_Forward(ACT_ID_ANY, ACT_ID_MESSAGES_DISTRI_DELETE_STATUS, &FuncList, (void *)pDeleteSts);
    pTemp = (INT8 *)lv_label_get_text(pDeleteSts->ContLabel.Label);
    Hal_Mem_Set(str, 0, 20);
    pTemp = strcpy(str, pTemp);
    j     = strlen(g_MsgGlobalCtrl.pDistriListName);

    pTemp = Hal_Mem_Alloc(j + 21);
    Hal_Mem_Set(pTemp, 0, j + 21);
    strcpy(pTemp, str);
    strcat(pTemp, g_MsgGlobalCtrl.pDistriListName);
    lv_label_set_text(pDeleteSts->ContLabel.Label, pTemp);
    Hal_Mem_Free(pTemp);

    for (j = 0; j < g_MsgGlobalCtrl.pDisList->DistriCnt; j++)
    {
        if (j)
        {
            pNode = _lv_ll_get_next(g_MsgGlobalCtrl.pDisList->pDisListInfo, pNode);
        }
        else
        {
            pNode = _lv_ll_get_head(g_MsgGlobalCtrl.pDisList->pDisListInfo);
        }
        if (false == strcmp(pNode->pListName, g_MsgGlobalCtrl.pDistriListName))
        {
            data1 = (NV_UI_Sms_Distribution_Contacts_List_t *)Hal_Mem_Alloc(sizeof(NV_UI_Sms_Distribution_Contacts_List_t));
            Hal_Mem_Set(data1, 0, sizeof(NV_UI_Sms_Distribution_Contacts_List_t));
            UI_NV_Read_Req(NV_SECTION_UI_SMS_DIST_CONT_LIST, 0, sizeof(NV_UI_Sms_Distribution_Contacts_List_t), (UINT8 *)data1);
            data2 = (NV_UI_Sms_Distribution_Contacts_List_t *)Hal_Mem_Alloc(sizeof(NV_UI_Sms_Distribution_Contacts_List_t));
            Hal_Mem_Set(data2, 0, sizeof(NV_UI_Sms_Distribution_Contacts_List_t));
            for (j = 0; j < data1->Count; j++)
            {
                if (j != (((pNode->NvAddrOffset - 1) / NV_SMS_MAX_LIST_NUM) / NV_SMS_MAX_NAME_NUM))
                {
                    Hal_Mem_Copy(&(data2->ContactsList[k]), &(data1->ContactsList[j]), sizeof(NV_UI_Sms_Distribution_Contact_Name_t));
                    k++;
                }
            }
            if(data1->Count > 0)
            {
                data2->Count = data1->Count - 1;
            }
            UI_NV_Write_Req(NV_SECTION_UI_SMS_DIST_CONT_LIST, 0, sizeof(NV_UI_Sms_Distribution_Contacts_List_t), (UINT8 *)data2);
            Hal_Mem_Free(data1);
            data1 = NULL;
            Hal_Mem_Free(data2);
            data2 = NULL;

            g_MsgGlobalCtrl.pDisList->DistriCnt -= 1;
            _lv_ll_remove(g_MsgGlobalCtrl.pDisList->pDisListInfo, pNode);
            Hal_Mem_Free(pNode->pListName);
            pNode->pListName = NULL;
            Hal_Mem_Free(pNode);
            pNode = NULL;
            Hal_Mem_Free(g_MsgGlobalCtrl.pDistriListName);
            g_MsgGlobalCtrl.pDistriListName = NULL;
            break;
        }
    }
    data = (NV_UI_Sms_Distribution_List_t *)Hal_Mem_Alloc(sizeof(NV_UI_Sms_Distribution_List_t));
    Hal_Mem_Set(data, 0, sizeof(NV_UI_Sms_Distribution_List_t));
    data->Count = g_MsgGlobalCtrl.pDisList->DistriCnt;
    for (j = 0; j < g_MsgGlobalCtrl.pDisList->DistriCnt; j++)
    {
        if (j)
        {
            pNode = _lv_ll_get_next(g_MsgGlobalCtrl.pDisList->pDisListInfo, pNode);
        }
        else
        {
            pNode = _lv_ll_get_head(g_MsgGlobalCtrl.pDisList->pDisListInfo);
        }
        Hal_Mem_Copy(data->DistriList[j].ListName, pNode->pListName, NV_SMS_MAX_NAME_NUM);
    }
    if (0 == g_MsgGlobalCtrl.pDisList->DistriCnt)
    {
        Hal_Mem_Free(g_MsgGlobalCtrl.pDisList->pDisListInfo);
        g_MsgGlobalCtrl.pDisList->pDisListInfo = NULL;
    }
    UI_NV_Write_Req(NV_SECTION_UI_SMS_DIST_LIST, 0, sizeof(NV_UI_Sms_Distribution_List_t), (UINT8 *)data);
    Hal_Mem_Free(data);
    data = NULL;
    // 2s timer start
    Sms_Timer_Create_And_Start(callback, ACT_ID_MESSAGES_DISTRI_DELETE_STATUS);
    // call back:Sms_Distribution_Lists_Add_Name_Timeout
    return(LV_RES_OK);
} /* Sms_Distribution_Lists_Delete_List_OK */
